class MyPromise {
    constructor(executor) {
      // 省略了Promise构造函数的完整实现细节
      // ...
    }
  
    static all(promises) {
      return new MyPromise((resolve, reject) => {
        const results = [];
        let completedCount = 0;
  
        if (!Array.isArray(promises)) {
          reject(new TypeError('Expected an array'));
          return;
        }
  
        promises.forEach((promise, index) => {
          if (typeof promise.then !== 'function') {
            reject(new TypeError(`Expected a Promise at index ${index}`));
            return;
          }
  
          promise.then(
            value => {
              results[index] = value;
              completedCount++;
  
              if (completedCount === promises.length) {
                resolve(results);
              }
            },
            error => {
              reject(error);
            }
          );
        });
      });
    }
  }
  
  // 使用示例：
  const p1 = new MyPromise(resolve => setTimeout(() => resolve(1), 1000));
  const p2 = new MyPromise(resolve => setTimeout(() => resolve(2), 500));
  const p3 = new MyPromise((resolve, reject) => setTimeout(() => reject(new Error('Rejected')), 200));
  
  MyPromise.all([p1, p2, p3]).then(values => console.log(values)).catch(err => console.error(err));